﻿using Lufei_CaterBLL;
using Lufei_CaterModel;
using Lufei_CaterUI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ItcastCater
{
    public partial class FrmUpdateMemmberInfo : Form
    {
        public FrmUpdateMemmberInfo()
        {
            InitializeComponent();
        }

        private void FrmUpdateMemmberInfo_Load(object sender, EventArgs e)
        {
            cmbMemType.DisplayMember = "MemTpName";
            cmbMemType.ValueMember = "MemType";
            //创建MemmberType对象
            MemmberTyoeBLL bll = new MemmberTyoeBLL();
            cmbMemType.DataSource= bll.GetMemmberType();
            cmbMemType.SelectedValue = mi.MemType;
        }

        MemmberInfo mi = null;
        /// <summary>
        /// 给窗体数据赋值
        /// </summary>
        public void SetValue(object sender,EventArgs e)
        {
            UpdateMemmberInfo<MemmberInfo> u = e as UpdateMemmberInfo<MemmberInfo>;
            if (u!=null)
            {
                //获取了FrmMemmber窗体传递过来的MemmberInfo对象
                 mi= u.obj;
                //给当前窗体的控件进行赋值
                txtMemNum.Text = mi.MemNum.ToString();
                txtMemName.Text= mi.MemName.ToString();
                if (mi.MemGender=="男")
                {
                    rdoMan.Checked = true;
                }
                else
                {
                    rdoWomen.Checked = true;
                }
                txtmemMoney.Text = mi.MemMoney.ToString();
                txtMemIntegral.Text = mi.MemIntegral.ToString();
                txtBirs.Text=mi.MemBirthdaty.ToString();
                txtMemPhone.Text=mi.MemPhone.ToString();
                txtMemDiscount.Text = mi.MemDiscount.ToString();
                dtEndServerTime.Text = mi.MemEndServerTime.ToString();

                //todo cmb数据问题
                //cmbMemType.SelectedValue=mi.MemType.ToString();
            }
        }

        private void btnOk_Click(object sender, EventArgs e)
        {

            //在ui层把要更新的数据封装成一个对象传递到BLL层
            //BLL层调用DAL层的方法（对象）
            MemmberInfo memmber = new MemmberInfo();
            memmber.MemNum = DateTime.Now.ToString();
            memmber.MemName = txtMemName.Text.Trim();
            memmber.MemGender = rdoMan.Checked ? "男" : "女";
            memmber.MemType = Convert.ToInt32(cmbMemType.SelectedValue);
            memmber.MemMoney = Convert.ToDecimal(txtmemMoney.Text.Trim());
            memmber.MemIntegral = Convert.ToInt32(txtMemIntegral.Text.Trim());//积分
            memmber.MemBirthdaty = Convert.ToDateTime(txtBirs.Text.Trim());
            memmber.MemMobilePhone = txtMemPhone.Text.Trim();
            memmber.MemDiscount = Convert.ToDecimal(txtMemDiscount.Text.Trim());
            memmber.MemEndServerTime = Convert.ToDateTime(dtEndServerTime.Text.Trim());
            memmber.MemmberId = mi.MemmberId;
            MemmverInfoBLL bll = new MemmverInfoBLL();
           bool idUpdate=  bll.UpdateMemmberInfo(memmber);
            if (idUpdate)
            {
                MessageBox.Show("修改成功");
                this.Close();
            }
            else
            {
                MessageBox.Show("修改失败");
                this.Close();
            }

        }
    }
}
